package com.project.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;

@RestController
@RequestMapping("user")
public class UserController {
    @RequestMapping("login")
    public String login(String userName, String pwd ,HttpServletRequest  request){
        if ("java".equals(userName)&&"123".equals(pwd)){
            request.getSession().setAttribute("loginUser",userName);
            return "ok";
        }
        return null;
    }
    @RequestMapping("add")
    public String add(String userName,@RequestParam("face") MultipartFile mf) throws IOException {
        //得到客户端上传的文件名
        String filename = mf.getOriginalFilename();
        //将上传的二进制数据保存到服务器本地文件
        mf.transferTo(new File("E:\\javaWeb\\interceptor\\src\\main\\resources\\static\\userface/"+filename));
        System.out.println(filename);
        return "ok";
    }
}
